package sedev.shopping.business;

import sedev.shopping.data.BinhLuanDAO;
import sedev.shopping.entities.BinhLuan;
import sedev.shopping.entities.ListBinhLuan;
import sedev.shopping.util.Paging;

public class BinhLuanService {
	
	public static boolean addData(BinhLuan data){
		BinhLuanDAO dao = new BinhLuanDAO();
		return dao.addData(data);
	}
	
	public static boolean updateData(BinhLuan data){
		BinhLuanDAO dao = new BinhLuanDAO();
		return dao.updateData(data);
	}
	
	public static boolean removeData(long id){
		BinhLuanDAO dao = new BinhLuanDAO();
		return dao.removeData(id);
	}
	
	public static BinhLuan getData(long id){
		BinhLuanDAO dao = new BinhLuanDAO();
		return dao.getData(id);		
	}
	
	public static ListBinhLuan getListDataByProductId(long san_pham_id, Paging paging){
		StringBuilder field = new StringBuilder();
		field.append(BinhLuan.Properties.id.name());
		field.append(",").append(BinhLuan.Properties.binh_luan_id.name());
		field.append(",").append(BinhLuan.Properties.user_id.name());		
		field.append(",").append(BinhLuan.Properties.noi_dung.name());
		field.append(",").append(BinhLuan.Properties.ngay_dang.name());
		
		StringBuilder condition = new StringBuilder();
		condition.append(BinhLuan.Properties.san_pham_id.name()).append("=").append(san_pham_id);
		
		BinhLuanDAO dao = new BinhLuanDAO();
		return dao.getListData(field.toString(), condition.toString(), "", paging);
	}

}
